package b1.scenes.home.wanted
{
	import b1.net.*;
	import b1.players.*;
	
	import com.greensock.TweenLite;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.text.*;
	import flash.ui.Mouse;
	
	
	public class WantedIcon extends Sprite
	{
		private var tempSprite:Sprite;
		private var myWidth:Number;
		private var myHeight:Number;
		private var myRank:Number;
		public var wantedMes:WantedMes;
		
		public function WantedIcon(animal:AnimalInfo,rank:int) 
		{
			super();
			tempSprite = new Sprite();
			//海报框背景
			myRank = rank;
			var WantedPostBgr:Class = ResourceHelper.getInstance().getClassByName("WantedPostBgr");
			var wantedPostBgr:Sprite = new WantedPostBgr();
			wantedPostBgr.x = 0;
			wantedPostBgr.y = 0;
			var width:int = wantedPostBgr.width;
			var height:int = wantedPostBgr.height; 
			myWidth=width;
			myHeight=height;
			tempSprite.addChild(wantedPostBgr);
			
			//动物头像
			var AnimalImage:Class = ResourceHelper.getInstance().getClassByName("Animal" + animal.animalIndex + "_1");
			var animalSprite:Sprite = new AnimalImage();
			var scale:Number = 2;
			animalSprite.width = width * 0.8;
			animalSprite.height = height *0.8;
			animalSprite.x = wantedPostBgr.x + (wantedPostBgr.width - animalSprite.width)/2;
			animalSprite.y = wantedPostBgr.y + wantedPostBgr.height - animalSprite.height;
			
			//animalSprite.scaleX = scale;
			//animalSprite.scaleY = scale;
			tempSprite.addChild(animalSprite);
			//通缉令海报
			var WantedPost:Class = ResourceHelper.getInstance().getClassByName("WantedPost");
			var wantedPost:Sprite = new WantedPost();
			wantedPost.width = width;
			wantedPost.height = height;
			wantedPost.x = wantedPostBgr.x - (wantedPost.width - wantedPostBgr.width)/2;
			wantedPost.y = wantedPostBgr.y -(wantedPost.height - wantedPostBgr.height) / 2;
			tempSprite.addChild(wantedPost);
			//姓名
			var titleText:TextField = new TextField();
			titleText.selectable = false;
			if(rank == 0) 
			{
				titleText.defaultTextFormat = new TextFormat("微软雅黑",9, 0x000000);
			}
			else 
			{
				titleText.defaultTextFormat = new TextFormat("微软雅黑",7, 0x000000);
			}
			titleText.text="微软";
			titleText.width = width * 0.4;
			titleText.height = height * 0.08;
			titleText.x = x + (width-titleText.textWidth) * 0.5;
			titleText.y = y + height * 0.77;
			tempSprite.addChild(titleText);
			var titleText1:TextField = new TextField();
			titleText1.selectable = false;
			if(rank == 0) 
			{
				titleText1.defaultTextFormat = new TextFormat("微软雅黑",9, 0x000000);
			}
			else 
			{
				titleText1.defaultTextFormat = new TextFormat("微软雅黑",7, 0x000000);
			}
			titleText1.text=(String) ((5 - rank) * 5000);
			titleText1.width = width * 0.4;
			titleText1.height = height * 0.08;
			titleText1.x = x + (width-titleText1.textWidth) * 0.5;
			titleText1.y = y + height * 0.85;
			tempSprite.addChild(titleText1);
			addChild(tempSprite);
			tempSprite.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			tempSprite.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			var scale:Number;
			if(myRank == 0)
			{
				scale = 1.2;
			}
			else scale = 1.3;
			TweenLite.to(tempSprite, 0.5, {scaleX:scale, scaleY:scale, x:0 - (scale - 1) * myWidth / 2, y:0 - (scale - 1) * myHeight / 2});
			wantedMes = new WantedMes(myRank);
			wantedMes.x = myWidth;
			wantedMes.y = myHeight *0.2;
			addChild(wantedMes);
			
			
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			removeChild(wantedMes);
			Mouse.cursor = "auto";
			TweenLite.to(tempSprite, 0.5, {scaleX:1, scaleY:1, x:0, y:0});
			
		}

	}
}